//
//  SetUpInforViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/28.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "SetUpInforViewModel.h"
#import "SetUpTableViewCell.h"
#import "SetUpHeaderView.h"

@interface SetUpInforViewModel ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation SetUpInforViewModel

-(instancetype)initWithViewToViewModel:(UITableView *)tableView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewModel:tableView theSuperView:superView]) {
        superView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        tableView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        tableView.mj_footer.hidden = YES;
        tableView.mj_header.hidden = YES;
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.rowHeight = kHeightProportion_In_iPhoneTriploid(44);
        tableView.tableHeaderView = [self createHeaderView];
        [superView addSubview:tableView];
        if (self.userInforData.length>0) {
            tableView.height = tableView.height - kHeightProportion_In_iPhoneTriploid(44);
            GLGWButton * bottomBut = [[GLGWButton alloc] initWithFrame:CGRectMake(0, kY_With_View(tableView, 0), KScreenWidth, kHeightProportion_In_iPhoneTriploid(44)) titleText:@"退出登录" titleLableFont:SYSTEMFONT(16) titleLableColor:[UIColor whiteColor] inSuperView:superView];
            bottomBut.backgroundColor = kColor_Rule_Yellow;
            [bottomBut addTarget:self action:@selector(exitAction) forControlEvents:UIControlEventTouchUpInside];
        }        
    }
    return self;
}

-(UIView *)createHeaderView{
    SetUpHeaderView * headerView = [[SetUpHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(119))];
    return headerView;
}

-(void)exitAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(exitAccount)]) {
        [self.delegate exitAccount];
    }
}

#pragma mark -- UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SetUpTableViewCell * cell = [SetUpTableViewCell cellWithTableView:tableView];
    cell.showPush = YES;
    switch (indexPath.section) {
        case 0:{
            if (indexPath.row == 0) {
                cell.leftstring = @"账号与安全";
            }else{
                cell.leftstring = @"个人信息";
            }
        }
            break;
        case 1:{
            if (indexPath.row == 0) {
                cell.leftstring = @"通知设置";
            }else{
                cell.leftstring = @"绑定设置";
            }
        }
            break;
        case 2:{
            if (indexPath.row == 0) {
                cell.leftstring = @"认证管理";
            }else{
                cell.leftstring = @"关于钢来钢往";
            }
        }
            break;
            
        default:
            break;
    }
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kHeightProportion_In_iPhoneTriploid(10))];
    return headerView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return kHeightProportion_In_iPhoneTriploid(10);
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.delegate && [self.delegate respondsToSelector:@selector(setUpDidSelectRowAtIndexPath:)]) {
        [self.delegate setUpDidSelectRowAtIndexPath:indexPath];
    }
}

@end
